package paperToChaKanChengJi.adapter

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import kotlinx.android.synthetic.main.item_analysis.view.*
import paperToChaKanChengJi.data.StuScore

/**
 * Created by Dadong on 2020/3/26
 * Describe: 学生得分分析
 */
class AnalysisAdapter(
        layoutResId: Int, data:  MutableList<StuScore>
) : BaseQuickAdapter<StuScore, BaseViewHolder>(layoutResId, data) {

    override fun convert(helper: BaseViewHolder, item: StuScore?) {
        with(helper.itemView) {
            when (item!!.Rank) {
                "1" -> {
                    rank_iv.visibility = View.VISIBLE
                    rank_iv.setImageResource(R.mipmap.icon_first)
                    rank_tv.visibility = View.GONE
                }
                "2" -> {
                    rank_iv.visibility = View.VISIBLE
                    rank_iv.setImageResource(R.mipmap.icon_second)
                    rank_tv.visibility = View.GONE
                }
                "3" -> {
                    rank_iv.visibility = View.VISIBLE
                    rank_iv.setImageResource(R.mipmap.icon_third)
                    rank_tv.visibility = View.GONE
                }
                else -> {
                    rank_tv.visibility = View.VISIBLE
                    rank_iv.visibility = View.GONE
                    rank_tv.text = item.Rank
                }
            }
            when (item.Section) {
                "优秀" -> {
                    state_tv.text = "优秀"
                    scoring_tv.setTextColor(helper.itemView.resources.getColor(R.color.c0ACD81))
                }
                "良好" -> {
                    state_tv.text = "良好"
                    scoring_tv.setTextColor(helper.itemView.resources.getColor(R.color.c5498FF))
                }
                "合格" -> {
                    state_tv.text = "合格"
                    scoring_tv.setTextColor(helper.itemView.resources.getColor(R.color.cFF9137))
                }
                "不合格" -> {
                    state_tv.text = "不合格"
                    scoring_tv.setTextColor(helper.itemView.resources.getColor(R.color.cF97878))
                }
                else -> {
                    state_tv.text = item.Section
                    scoring_tv.setTextColor(helper.itemView.resources.getColor(R.color.c666666))
                }
            }
            name_tv.text = item.StuName
            if (item.Score == "--") {
                scoring_tv.text = item.Score
            } else {
                scoring_tv.text = "${item.Score}\n(${item.ScoreRate}%)"
            }
            score_tv.text = "${item.SubjectiveScore}|${item.ObjectiveScore}"
            duration_tv.text = item.AnswerLength
        }
    }

}